package com.alibaba.goods.user.account.service;

import com.alibaba.goods.user.account.dao.AccountDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @Author:RenPu
 * @Date: 2020/7/7 16:11
 * @Version: 1.0
 * @description:
 */

@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Resource
    private AccountDao accountDao;



    @Override
    public void decrease(Long userId, BigDecimal money) {

        log.info( "------------accout-service服务扣金额开始-------------" );
        //模拟超时异常，全局事务回滚
        //让线程暂停几秒钟 feign默认超时时间为1秒，fegin还有重试机制，异常发生时有可能会反复扣钱如果不加全局事务管控
//        try {
//            TimeUnit.SECONDS.sleep( 20 );
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        accountDao.decrease( userId,money );
        log.info( "------------accout-service服务扣金额结束-------------" );

    }
}
